package com.lannuokeji.utils.tags.map;

import java.util.Map;

import org.beetl.core.GeneralVarTagBinding;
import org.beetl.core.exception.BeetlException;

/**
 * 顶部导航标签
 * @author zzp
 * 调用示例：<#dataPage table="g_cms_column";dataPage>
		@@for(r in dataPage.List) {
			<li><a href="">${r.name}</a></li>
		@@}
		</#dataPage>
 */
public class DataPageTag extends GeneralVarTagBinding {

	public static String tagName = "dataPage";
	
	@Override
	public void render() {
		Map<String, String> attrs = (Map<String, String>) this.args[1];
		// 接收所要查询的参数，如果为空那么赋值为*
		String getFields = attrs.get("fields");
		String fields = (getFields == null) ? "*" : getFields;

		String sqlExceptSelect = " from ";

		// 接收传过来的表名，没有表名不行
		String tableName = attrs.get("table");
		if (tableName == null) {
			return;
		}
		sqlExceptSelect += tableName;
		
		// 接收where需要拼接的条件
		String where = attrs.get("where");
		if (where != null) {
			sqlExceptSelect += " where ";
			sqlExceptSelect += where;
		}
		// 排序
		String orderBy = attrs.get("orderBy");
		if (orderBy != null) {
			sqlExceptSelect += " order by ";
			sqlExceptSelect += orderBy;
		}
		int pageNumber = attrs.get("pageNumber") != null ? Integer.parseInt(attrs.get("pageNumber")) : 1;
		int pageSize = attrs.get("pageSize") != null ? Integer.parseInt(attrs.get("pageSize")) : 10;
				
//		Page<Record> dataPage = Db.paginate(pageNumber, pageSize
//				, "select " + fields, sqlExceptSelect);
//		this.binds(dataPage);
		this.doBodyRender();
	}

}
